package JD;
import java.util.Scanner;

public class Main2 {
    public static void main(String[] args) {
        Scanner cin=new Scanner(System.in);
        int T=cin.nextInt();
        for (int t = 0; t < T; t++) {
            int n=cin.nextInt();
            cin.nextLine();
            char[] chars = cin.nextLine().toCharArray();
            int[] nums=new int[3];
            for (char c:chars) {
                nums[c-'A']++;
            }
            int res=0;
            for (int i = 0; i < nums.length; i++) {
                if (nums[i]>n){
                    res+=(nums[i]-n);
                    nums[i]-=n;
                }else {
                    nums[i]=0;
                }
            }
            if (res==0){
                System.out.println(res);
                continue;
            }
            for (int i = 0; i < chars.length; i++) {

            }
            System.out.println(res);
        }
    }
}
